package com.dms.wuziqi.controller;

import com.dms.wuziqi.JwtUtil.JwtUtil2;
import com.dms.wuziqi.Result.Result;
import com.dms.wuziqi.fliter.Role;
import com.dms.wuziqi.pojo.Manager;
import com.dms.wuziqi.pojo.User;
import com.dms.wuziqi.service.ManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin(origins = "*")
public class ManagerController {
    @Autowired
    ManagerService managerService;
    @PostMapping("/managerLogin")
    public Result managerLogin(@RequestBody Manager manager){
        Manager manager1=managerService.findManager(manager.getManagerName(), manager.getManagerPwd());
        System.out.println(manager);
        if (manager1!=null){
            Map<String,Object> claims=new HashMap<>();
            claims.put("userId",manager1.getManagerId());
            claims.put("role","rooter");
            String token= JwtUtil2.genToken(claims);
            return Result.success(token);
        }else {
            return Result.error("登陆失败，请检查");
        }
    }
    @GetMapping("/getAllUser")
    @Role(role = "rooter")
    public Result getAllUser(){
        List<User> list=managerService.findAllUser();
        return Result.success(list);
    }
    @PostMapping("/login")
    public Result login(@RequestBody Manager manager){
        System.out.println(manager);
        return Result.success();
    }

}
